﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using Convertor.Interface;
using Wpf.CommonTools;
using Wpf.CommonTools.SystemExtension;
using Wpf.CommonTools.StringExtension;

namespace Convertor.Plugin.AlertBox
{
    public enum AlertTypes
    {
        OutputContent,
        InputContent,
        CustomContent
    }

    public enum MessageBoxButtonTypes
    {
        OK = 0,
        OKCancel = 1,
    }

    [Serializable]
    public class ConfigContent : IConfigContent, ISerializable, ICloneable, INotifyPropertyChanged
    {
        private AlertTypes alertType;

        public AlertTypes AlertType
        {
            get { return alertType; }
            set { alertType = value; if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs("ToolTip")); } }
        }
        private string customContent;

        public string CustomContent
        {
            get { return customContent.ToLimitLength(1000); }
            set { customContent = value; if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs("ToolTip")); } }
        }

        public override string ToString()
        {
            return ToolTip;
        }

        public ConfigContent()
        {
        }

        #region IToolTip 成员

        public string ToolTip
        {
            get
            {
                string a;
                switch (this.alertType)
                {
                    default:
                    case AlertTypes.CustomContent:
                        a = string.Format(UILanguage.FindResource("Plugin_AlertBox_ToolTip_Custom"), this.customContent.ToLimitLength(20));
                        break;
                    case AlertTypes.InputContent:
                    case AlertTypes.OutputContent:
                        a = string.Format(UILanguage.FindResource("Plugin_AlertBox_ToolTipOutputInput"),
                            UILanguage.FindResource("Plugin_AlertBox_AlertType_" + this.alertType));
                        break;
                }
                return a;
            }
        }

        #endregion

        #region ISerializable 成员

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("AlertType", AlertType, typeof(AlertTypes));
            info.AddValue("CustomContent", CustomContent, typeof(string));
        }

        public ConfigContent(SerializationInfo info, StreamingContext context)
        {
            AlertType = (AlertTypes)info.GetValue("AlertType", typeof(AlertTypes));
            CustomContent = (string)info.GetValue("CustomContent", typeof(string));
        }

        #endregion

        #region ICloneable 成员

        public object Clone()
        {
            ConfigContent content = new ConfigContent()
            {
                AlertType = this.AlertType,
                CustomContent = this.CustomContent
            };
            return content;
        }

        #endregion

        #region INotifyPropertyChanged 成员

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

    }
}
